package fei.yuzhi.com.loveflowers.fragment.firstpagefragment.searchresult;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import fei.yuzhi.com.loveflowers.R;
import fei.yuzhi.com.loveflowers.bean.searchbean.GoodsListBean;
import fei.yuzhi.com.loveflowers.utils.MyListView;

/**
 * Created by My on 2016/10/16.
 */
public class SearchResultActivity extends AppCompatActivity implements SearchResultContract
        .SearchingView {
    @BindView(R.id.search_result_lv)
    MyListView searchResultLv;
    Handler handler=new Handler();
    SearchResultPresenter presenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_searchresult);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        String keyword = intent.getStringExtra("keyword");
        presenter = new SearchResultPresenter(this);
        presenter.getBean(keyword);
    }

    @Override
    public void onGetSearchBeanSuccess(final List<GoodsListBean> goodsListBeanList) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                SearchResultListAdapter adapter=new SearchResultListAdapter(SearchResultActivity.this,goodsListBeanList);
                searchResultLv.setAdapter(adapter);
            }
        });
    }

    @Override
    public void onGetSearchBeanFail(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}
